package com.doeis.minaserver.container;


import com.doeis.minaserver.NettyServer;
import com.doeis.minaserver.packet.InfoPacket;
import com.doeis.minaserver.packet.ServerPacketFactory;
import com.doeis.minaserver.session.ClientConnection;

public class BasicModule  implements Module  {
	
	private String name;
	
	protected NettyServer server;
	
	public BasicModule(String moduleName){
		this.name = moduleName;
	}
	
	/**
	 * 初始化模块
	 * @param server
	 */
	public  void initialize(NettyServer server){};
	
	/**
	 * 启动模块
	 */
	public void start(){};
	
	/**
	 * 结束模块，释放资源
	 */
	public void stop(){}
	

	@Override
	public void destroy() {
	}
	
	@Override
	public String getName(){
		return name;
	}
	
	protected void sendSystemPacket(ClientConnection conn, String to, String text, int type,byte cmd){
		InfoPacket info = ServerPacketFactory.systemMsg(to, text, type,cmd);
		if(conn != null){
			conn.deliver(info);
		}
	}
	
	protected void sendLoginErrorTip(ClientConnection conn, String to, String text){
		sendSystemPacket(conn, to, text, InfoPacket.NT_SRV_LOGIN_ERROR,InfoPacket.NOTIFY_SRV_MSG);
		//conn.close();
	}

	
	
}

